package br.com.senac.pi5.comum;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class ComumBO {

    public double getDistance(double lat1, double lat2, double lon1, double lon2) {

        final int R = 6371; // Raio da Terra

        Double latDistance = deg2rad(lat2 - lat1);
        Double lonDistance = deg2rad(lon2 - lon1);
        Double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2)
                + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2))
                * Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2);
        Double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        double distance = R * c * 1000; // convert to meters

        distance = Math.pow(distance, 2) + Math.pow(0, 2);
        return Math.sqrt(distance) / 1000;
    }

    public double deg2rad(double deg) {
        return (deg * Math.PI / 180.0);
    }

    public double getExecutivePrice(double distance) {
        return distance * 0.8;
    }

    public double getEconomicPrice(double distance) {
        return distance * 0.5;
    }

    public double arredondarPreco(double preco) {
        double valorFormatado = Double.valueOf(String.format(Locale.US, "%.2f", Math.ceil(preco)));
        return valorFormatado;
    }

    public List<String> listarPoltronas() {
        List<String> poltronas = new ArrayList<String>();

        for (int i = 1; i < 25; i++) {
            poltronas.add("A" + i);
        }

        for (int i = 1; i < 21; i++) {
            poltronas.add("B" + i);
        }

        for (int i = 1; i < 21; i++) {
            poltronas.add("C" + i);
        }

        for (int i = 1; i < 21; i++) {
            poltronas.add("D" + i);
        }

        for (int i = 1; i < 21; i++) {
            poltronas.add("E" + i);
        }

        for (int i = 1; i < 21; i++) {
            poltronas.add("F" + i);
        }

        for (int i = 1; i < 21; i++) {
            poltronas.add("G" + i);
        }

        return poltronas;
    }

    public List<String> removerEListarPoltronas(List<String> poltronas, String poltrona) {

        if (poltrona.equals("0")) {
            for (String poltronaCorrente : poltronas) {
                if (poltronaCorrente.equals(poltrona)) {
                    poltronas.remove(poltronaCorrente);
                    break;
                }
            }
        }

        return poltronas;
    }
}
